package com.shhm.common.dto.security;

import com.shhm.common.entity.admin.SysRoleOperatePerms;
import com.shhm.common.entity.admin.SysUser;
import com.shhm.common.entity.system.UserDetailResp;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/7 下午5:14
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SecurityUser extends UserDetailResp implements UserDetails {
    private List<String> roles;

    private SysRoleOperatePerms currentPerms;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roles.stream()
                .map(role -> (GrantedAuthority) () -> role)
                .toList();
    }

    public void copySysUser(SysUser sysUser) {
        BeanUtils.copyProperties(sysUser, this);
    }
}
